package top.lingkang.potato.views;

import cn.hutool.core.lang.Assert;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.controlsfx.control.MaskerPane;

import java.io.IOException;
import java.net.URL;

public class LoginView extends Stage {

    public static SimpleBooleanProperty showLoginMaskerPane = new SimpleBooleanProperty(false);

    public LoginView() {
        super();
        URL resource = getClass().getResource("/fxml/login.fxml");
        Assert.isFalse(resource == null, "加载fxml失败！");
        VBox root = null;
        try {
            root = FXMLLoader.load(resource);
        } catch (IOException e) {
            e.printStackTrace();
            Assert.isNull(e, e.getMessage());
        }

        StackPane body = new StackPane();
        // 铺满屏幕
        body.setPadding(new Insets(-10, 0, 0, 0));
        MaskerPane loginMaskerPane = new MaskerPane();
        loginMaskerPane.setText("登录中...");
        loginMaskerPane.setVisible(false);
        body.getChildren().addAll(root, loginMaskerPane);
        setScene(new Scene(body));
        getIcons().add(new Image("assets/img/potato.png"));
        show();

        // 登录遮罩监听
        showLoginMaskerPane.addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue<? extends Boolean> observableValue, Boolean aBoolean, Boolean t1) {
                loginMaskerPane.setVisible(observableValue.getValue());
            }
        });
    }

}
